package com.axc.gallery2.view;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;

/** 
 * 异步读取网络图片 
 */ 
public class AsyncLoadImage extends AsyncTask<Object, Object, Void> { 


	@Override 
	protected Void doInBackground(Object... params) { 
		ImageView imageView=(ImageView) params[0]; 
		String url=(String) params[1]; 
		Bitmap bitmap = BitmapFactory.decodeFile(url); 
		ProgressBar progressBar = null;
		if(params.length==3){
			progressBar=(ProgressBar) params[2];
			publishProgress(new Object[] {imageView, bitmap,progressBar}); 
		}else{
			publishProgress(new Object[] {imageView, bitmap}); 
		}
		return null; 
	} 
	protected void onProgressUpdate(Object... progress) { 
		ImageView imageView = (ImageView) progress[0]; 
		imageView.setImageBitmap((Bitmap) progress[1]); 
		if(progress.length==3){

			ProgressBar progressBar = (ProgressBar) progress[2];
			progressBar.setVisibility(View.GONE);
		}
	} 


	public static Bitmap getBitmapByUrl(String url) {	
		return SampleSize.getSampleSize(url);
	} 
}